<?php

namespace common\model;

use think\model\RelationModel;

class RoleModel extends RelationModel
{
    const BUSINESS_PRODUCER_CODE = 'business_producer';  // 商务制片
    const TENANT_ADMINISTRATOR_CODE = 'tenant_administrator'; // 租户管理员

    //自动验证
    protected $_validate = [
        ['name', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['name', '1,128', '', self::EXISTS_VALIDATE, 'length'],
        ['name', '', '', self::EXISTS_VALIDATE, 'unique'],
        ['code', '1,64', '', self::EXISTS_VALIDATE, 'length'],
        ['code', '', '', self::EXISTS_VALIDATE, 'alphaDash'],
        ['code', '', '', self::EXISTS_VALIDATE, 'unique'],
        ['type', ['system', 'custom'], '', self::EXISTS_VALIDATE, 'in'],
        ['is_platform', ['yes', 'no'], '', self::EXISTS_VALIDATE, 'in']
    ];

    // 自动完成
    protected $_auto = [
        ['code', 'auto_fill_code', self::MODEL_INSERT, 'function_with_data'],
        ['type', 'auto_fill_role_type', self::MODEL_INSERT, 'function_with_data'],
        ['created_by', 'fill_created_by', self::MODEL_INSERT, 'function'],
        ['created', 'time', self::MODEL_INSERT, 'function']
    ];

    /**
     * 获取器：创建时间
     * @param $value
     * @param $data
     * @return array|mixed
     */
//    public function getCreatedAttr($value, $data)
//    {
//        if (!empty($value)) {
//            return get_format_date($value, 1);
//        }
//        return "";
//    }
}
